package com.java.collection;

import java.util.HashMap;
import java.util.Map;

public class HashMapDemo {
    public static void main(String[] args) {
        //创建HashMap
        Map<String, String> map = new HashMap<>();
        //添加数据
        map.put("001","张三");
        map.put("002","李四");
        map.put("003","王五");
        map.put("004","赵六");
        map.put("005","钱七");
        map.put("006","孙八");
        //查找数据
        System.out.println(map.get("001"));
        System.out.println(map.get("002"));
        //判断是否存在某个键
        System.out.println("数据是否存在："+map.containsKey("001"));
        System.out.println("数据是否存在："+map.containsValue("张三"));
        //遍历所有的key
        System.out.println("-------遍历所有的key-----");
        for (String key : map.keySet()) {
            System.out.println(key);
        }
        //遍历所有的value
        System.out.println("------遍历所有的value-------");
        for (String value : map.values()) {
            System.out.println(value);
        }
        //遍历集合
        System.out.println("-------遍历所有的键值对-------");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey()+"--"+entry.getValue());
        }
    }
}
